package com.example.springboot.controller.uploadFile;

import com.example.springboot.entity.FtpInformation;
import com.example.springboot.utils.FtpUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/7/26 16:07
 */
@RestController
@RequestMapping("/ftp")
public class UploadFileByFtpController {
    /**
     * @param ftpInformation
     * @param multipartFiles
     * @return
     */
    @PostMapping("/upload")
    public List<String> upload(FtpInformation ftpInformation, @RequestParam("file") MultipartFile[] multipartFiles) throws IOException {
        List<String> list = new ArrayList<>();
        // 遍历
        for (MultipartFile multipartFile : multipartFiles) {
            String fileName = FtpUtils.uploadFile(ftpInformation, multipartFile);
            list.add(fileName);
        }
        return list;
    }
}
